package com.li.o2oSystem.interceptor.shopadmin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.li.o2oSystem.entity.Shop;
/**
 * 店家管理操作验证，
 * @author Administrator
 *
 */
public class ShopPermissionInterception extends HandlerInterceptorAdapter {
	//操作前拦截，进行店家操作权限拦截
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler){
		//从session中获取选择的店铺
		Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");
		//从session中获取当前用户可操作的店铺列表
		List<Shop> shopList = (List<Shop>) request.getSession().getAttribute("shopList");
		//非空判断
		if(currentShop != null && shopList != null){
			//遍历可操作性的店铺列表
			for (Shop shop : shopList) {
				//如果店铺在可操作的列表里，返回true
				if(shop.getShopId() == currentShop.getShopId()){
					return true;
				}
			}
		}
		//不满足则返回false
		return false; 
	}
}
